<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let MyApp = {};

        MyApp.nameSpace = function (name) {  
            let parts = name.split('.');
            let current = MyApp;

            for (let i = 0; i < parts.length; i++) {
               if(!current[parts[i]]){
                current[parts[i]] = {}
               }

               current = current[parts[i]];
            }


        }

        MyApp.nameSpace('space1.space2');
        MyApp.nameSpace('space3');
        console.dir(MyApp);
    </script>
</body>
</html>